package com.example.phpclient.content;

import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;


import com.example.phpclient.DB.listview_cell_data;
import com.example.phpclient.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class ListView_activity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    public ListView listView;
    private ArrayAdapter<listview_cell_data> adapter;
    //item点击事件跳转到不同页面
//    private void toNewActivity(int position){
//        Intent intent;
//        switch (position){
//            case 0:
//                intent=new Intent(ListView_activity.this,Note.class);
//        }
//    }


    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view);



//        listArrayAdapter =new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1);//后面是列表项资源ID
        adapter = new ArrayAdapter<listview_cell_data>(this, R.layout.list_view_content);//后面是列表项资源内容

        //绑定layout里面的listview
        listView = (ListView) findViewById(R.id.listview1);
        listView.setAdapter(adapter);

        adapter.add(new listview_cell_data("张三", "B301", "已签到"));
        adapter.add(new listview_cell_data("李四", "B302", "已签到"));



//        listArrayAdapter.add("hello");


//        //生成动态数组加入数据
//        ArrayList<HashMap<String,Object>>listItem = new ArrayList<HashMap<String, Object>>();
//        for (int i =0;i<10;i++)
//        {
//            HashMap<String,Object>map=new HashMap<String,Object>();
//            map.put("ItemImage",R.drawable.student);
//            map.put("ItemTitle", "Level "+i);
//            map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves! ");
//            listItem.add(map);
//        }

//        //生成适配器的Item和动态数组对应的元素
//        SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源
//                R.layout.list_view_content,//ListItem的XML实现
//                //动态数组与ImageItem对应的子项
//                new String[] {"ItemImage","ItemTitle", "ItemText"},
//                //ImageItem的XML文件里面的一个ImageView,两个TextView ID
//                new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.Itemclass}
//        );
//        //添加并且显示
//        listView.setAdapter(listItemAdapter);

        //添加点击
        //添加长按点击
//        listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
//
//            @Override
//            public void onCreateContextMenu(ContextMenu contextMenu, View view, ContextMenu.ContextMenuInfo contextMenuInfo) {
//                contextMenu.setHeaderTitle("长按菜单-ContextMenu");
//                contextMenu.add(0, 0, 0, "弹出长按菜单0");
//                contextMenu.add(0, 1, 0, "弹出长按菜单1");
//            }
//        });
//    }

//    @Override
//    public boolean onContextItemSelected(@NonNull MenuItem item) {
//        setTitle("点击了长按菜单里面的第"+item.getItemId()+"个项目");
//        return super.onContextItemSelected(item);
//    }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        listview_cell_data data = adapter.getItem(i);

    }
}

